package com.jt.config;

import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration //标识，我是一个配置类，相当于application.xml
@ComponentScan("com.jt") //如果注解中只有value属性，则可以省略
@PropertySource(value = "classpath:/user.properties",encoding = "UTF-8")//作用：加载指定的pro配置文件，将数据保存到spring容器中
public class SpringConfig {
    //定义对象属性 准备接收数据
    //@Value(123) 将123赋值给ID
    @Value("${user.id}")
    private  Integer id;
    @Value("${user.username}")
    private  String  username;
   @Bean
    public User user(){
       User user = new User();
       user.setId(101);
       user.setName("Spring容器");
       return user;
   }
}
